package com.roc.steelend.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.roc.steelend.mapper.ComparisonMapper;
import com.roc.steelend.mapper.SmallTypeMapper;
import com.roc.steelend.pojo.SmallType;
import com.roc.steelend.service.ComparisonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ComparisonServiceImpl  implements ComparisonService {

    @Autowired
    private ComparisonMapper comparisonMapper;

    @Autowired
    private SmallTypeMapper smallTypeMapper;

    @Override
    public SmallType findJuanBanIdByPingBanId(Integer juanBanId) {
        Integer pingBanId = comparisonMapper.findJuanBanIdByPingBanId(juanBanId);
        QueryWrapper<SmallType> wrapper = new QueryWrapper<>();
        wrapper.eq("small_type_id",pingBanId);
        List<SmallType> smallTypes = smallTypeMapper.selectList(wrapper);
        SmallType smallType = smallTypes.get(0);
        return smallType;
    }

    @Override
    public List<HashMap<String, Object>> findAllComparison(){
        List<HashMap<String,Object>> list = new ArrayList<>();

        List<HashMap<String, Object>> allComparison = comparisonMapper.findAllComparison();
        for (int i = 0; i <allComparison.size() ; i++) {
            HashMap<String, Object> map = allComparison.get(i);
            Integer pingbanId =(Integer) map.get("pingban_id");
            QueryWrapper<SmallType> wrapper = new QueryWrapper<>();
            wrapper.eq("small_type_id",pingbanId);
            List<SmallType> smallTypes = smallTypeMapper.selectList(wrapper);
            SmallType smallType = smallTypes.get(0);
            map.put("pingBanName",smallType.getSmallTypeName());
            list.add(map);
        }
        return list;


    }
}
